﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HCFramework.API.LINQ;
using System.IO;

namespace HCFramework.Product.Detail.Control
{
    public partial class PropertyInfo : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public void BindData(API.LINQ.Product product)
        {
            List<ProductPropertyValue> listProductPropertyValue = product.ProductPropertyValues
                .OrderBy(ik => ik.ProductProperty.OrderDisplay).ToList();
            litProperties.Text = "";
            foreach (ProductPropertyValue ppv in listProductPropertyValue)
            {
                litProperties.Text += GetDisplayItem(ppv);
            }
        }

        private string GetDisplayItem(ProductPropertyValue ppv)
        {
            string ret = File.ReadAllText(Server.MapPath(@"~\Product\Detail\Template\PropertyItem.htm"));
            ret = ret.Replace("{propertyName}", ppv.ProductProperty.Name);
            ret = ret.Replace("{propertyValue}", ppv.Value);
            return ret;
        }
    }
}